﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_hh_thuoctinhInfo
    {
        private int _id_thuoctinh;
        private string _tenthuoctinh;
        private string _ghichu;

        public cs_erp_hh_thuoctinhInfo()
        {
            this._id_thuoctinh = 0;
            this._tenthuoctinh = " ";
            this._ghichu = " ";

        }
        public int id_thuoctinh
        {
            get
            {
                return this._id_thuoctinh;
            }
            set
            {
                this._id_thuoctinh = value;
            }
        }
        public string tenthuoctinh
        {
            get
            {
                return this._tenthuoctinh;
            }
            set
            {
                this._tenthuoctinh = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[4];
            paraName[0] = "@id_thuoctinh";
            paraName[1] = "@tenthuoctinh";
            paraName[2] = "@ghichu";
            paraName[3] = "@option";
            object[] paraValue = new object[4];
            paraValue[0] = this._id_thuoctinh;
            paraValue[1] = this._tenthuoctinh;
            paraValue[2] = this._ghichu;
            paraValue[3] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 4, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_HH_THUOCTINH", option);
        }

        
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_HH_THUOCTINH", "id_thuoctinh = " + this._id_thuoctinh);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                //this._id_thuoctinh = Convert.ToInt32(ds.Tables[0].Rows[0]["id_thuoctinh"].ToString().Trim());
                this._tenthuoctinh = ds.Tables[0].Rows[0]["tenthuoctinh"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }
        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_thuoctinh, tenthuoctinh, ghichu "
                + " from ERP_HH_THUOCTINH";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_List_Thuoctinh(int id_hh)
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.id_thuoctinh, a.tenthuoctinh, a.ghichu, b.sudung "
                + " from ERP_HH_THUOCTINH a, ERP_HH_TT b"
                + " where a.id_thuoctinh = b.id_thuoctinh and b.id_hh = " + id_hh
                + " union all "
                + " select a.id_thuoctinh, a.tenthuoctinh, a.ghichu, cast (0 as bit) as sudung"
                + " from ERP_HH_THUOCTINH a "
                + " where a.id_thuoctinh not in (select id_thuoctinh from ERP_HH_TT where id_hh = " + id_hh + " and sudung = 1)";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}